<!DOCTYPE html>
<html lang="zh-CN">
    <head>
  <!-- 元数据 -->
  <meta charset="utf-8">
  <link rel="icon" href="/blog/images/logo.png">
  
  <title>【Java 8 新特性】时间类：LocalDate | 溪岚花的博客</title>
  
  <meta name="author" content="林家隆" />
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="format-detection" content="telphone=no, email=no" />
  
    <meta name="keywords" content="Java" />
  
  <meta name="description" content="LocalDate 类用来表示日期，由三个成员变量 year 、 month 、 day 组成，大部分成员方法是操作三个成员变量的过程，如查询由这三个变量组成的其他的时间分量，对三个变量进行加、减或重新赋予新值等等操作。 公共常量123456789&#x2F;*** MAX：localDate对象能表示日期的最大值。* MIN：localDate对象能表示日期的最小值。*&#x2F;@Testpublic void">
<meta property="og:type" content="article">
<meta property="og:title" content="【Java 8 新特性】时间类：LocalDate">
<meta property="og:url" content="https://lin316.gitee.io/blog/2023/05/04/Java8/time/LocalDate/index.html">
<meta property="og:site_name" content="溪岚花的博客">
<meta property="og:description" content="LocalDate 类用来表示日期，由三个成员变量 year 、 month 、 day 组成，大部分成员方法是操作三个成员变量的过程，如查询由这三个变量组成的其他的时间分量，对三个变量进行加、减或重新赋予新值等等操作。 公共常量123456789&#x2F;*** MAX：localDate对象能表示日期的最大值。* MIN：localDate对象能表示日期的最小值。*&#x2F;@Testpublic void">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lin316.gitee.io/blog/blog/images/logo.png">
<meta property="article:published_time" content="2023-05-03T16:00:00.000Z">
<meta property="article:modified_time" content="2025-11-20T11:35:22.175Z">
<meta property="article:author" content="林家隆">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lin316.gitee.io/blog/blog/images/logo.png">
  
  <!-- 站点验证相关 -->
  
    
    
    
  
  <!-- 样式表文件 -->
  <link rel="stylesheet" id="kratos-css" href="/blog/css/kratosr.min.css" media="all"></script>
  
    <link rel="stylesheet" id="darkmode-css" href="/blog/css/kr-color-dark.min.css" media="(prefers-color-scheme: dark)"></script>
    <script src="/blog/js/kr-dark.min.js"></script>
  
  
    <link rel="stylesheet" id="highlight-css" href="/blog/css/highlight/night-eighties.min.css" media="all"></script>
  
  <link rel="stylesheet" id="fontawe-css" href="/blog/vendors/font-awesome@4.7.0/css/font-awesome.min.css" media="all"></script>
  <link rel="stylesheet" id="nprogress-css" href="/blog/vendors/nprogress@0.2.0/nprogress.css" media="all"></script>
  
  
  
    <link rel="stylesheet" href="/blog/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css"></script>
  
  <!-- 不得不预先加载的一些JS文件 -->
  <script src="/blog/vendors/jquery@3.6.0/dist/jquery.min.js"></script>
  
  
  <style>
    
    
  </style>
  
<meta name="generator" content="Hexo 6.3.0"></head>


    <body class="custom-background">
        <div id="kratos-wrapper">
    <div id="kratos-page">
        <div id="kratos-header">
            <header id="kratos-desktop-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="nav-header">
                        <nav id="kratos-menu-wrap">
                            <ul id="kratos-primary-menu" class="sf-menu">
                                
                                    
                                        <li>
                                            
                                                <a href="/blog/">
                                            
                                                
                                                    <i class="fa fa-home"></i>
                                                
                                                首页
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/archives/">
                                            
                                                
                                                    <i class="fa fa-file"></i>
                                                
                                                归档
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/tags/">
                                            
                                                
                                                    <i class="fa fa-tag"></i>
                                                
                                                标签
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/categories/">
                                            
                                                
                                                    <i class="fa fa-folder"></i>
                                                
                                                目录
                                            </a>
                                            
                                        </li>
                                    
                                        <li>
                                            
                                                <a href="/blog/search/">
                                            
                                                
                                                    <i class="fa fa-search"></i>
                                                
                                                搜索
                                            </a>
                                            
                                        </li>
                                    
                                
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
            <header id="kratos-mobile-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="color-logo"><a href="/blog/">溪岚花的博客</a></div>
                    <div class="nav-toggle">
                        <a class="kratos-nav-toggle js-kratos-nav-toggle">
                            <i></i>
                        </a>
                    </div>
                </div>
            </header>
        </div>
        <div class="kratos-start kratos-hero-2">
            <!-- <div class="kratos-overlay"></div> -->
            <div class="kratos-cover kratos-cover-2 text-center">
                <div class="desc desc2 animate-box">
                    <a href="/blog/">
                        <h2 style="opacity: 0.2;">溪岚花的博客</h2> <br />
                        <span></span>
                    </a>
                </div>
            </div>
        </div>

        <div id="kratos-blog-post">
            <div class="container">
                <div id="main" class="row">
                    

        

            <section class="col-md-8">

        

            <article itemscope itemtype="https://schema.org/Article">
    
    <link itemprop="mainEntityOfPage" href="https://lin316.gitee.io/blog/2023/05/04/Java8/time/LocalDate/">
    <div class="kratos-hentry kratos-post-inner clearfix">
        <header class="kratos-entry-header">
            
                <h1 class="kratos-entry-title text-center" itemprop="name headline">【Java 8 新特性】时间类：LocalDate</h1>
            
            
            <ul class="kratos-post-meta text-center">
                <li><time datetime="2023-05-03T16:00:00.000Z" itemprop="datePublished"><i class="fa fa-calendar"></i> 2023-05-04</time></li>
                <li itemprop="author" itemscope itemtype="https://schema.org/Person">
                    <i class="fa fa-user"></i> 作者 <span itemprop="name">林家隆</span>
                </li>
                
                    <li>
                        <i class="fa fa-edit"></i> 
                        
                        
                            14.96K
                        
                        字
                    </li>
                
                
            </ul>
        </header>
        <div class="kratos-post-content">
            
            <div id="expire-alert" class="alert alert-warning hidden" role="alert">
                <div class="icon"><i class="fa fa-warning"></i></div>
                <div class="text"><p>本文最后编辑于 <time datetime="1763638522175"></time> 前，其中的内容可能需要更新。</p></div>
            </div>
            
            
            
                <div class="kratos-post-inner-toc toc-div-class" >
                    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1%E5%B8%B8%E9%87%8F"><span class="toc-number">1.</span> <span class="toc-text">公共常量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="toc-number">2.</span> <span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal"><span class="toc-number">2.1.</span> <span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now"><span class="toc-number">2.2.</span> <span class="toc-text">now()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-ZoneId-zone"><span class="toc-number">2.3.</span> <span class="toc-text">now(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-Clock-clock"><span class="toc-number">2.4.</span> <span class="toc-text">now(Clock clock)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-int-year-int-month-int-dayOfMonth"><span class="toc-number">2.5.</span> <span class="toc-text">of(int year, int month, int dayOfMonth)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-int-year-Month-month-int-dayOfMonth"><span class="toc-number">2.6.</span> <span class="toc-text">of(int year, Month month, int dayOfMonth)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofEpochDay-long-epochDay"><span class="toc-number">2.7.</span> <span class="toc-text">ofEpochDay(long epochDay)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofYearDay-int-year-int-dayOfYear"><span class="toc-number">2.8.</span> <span class="toc-text">ofYearDay(int year, int dayOfYear)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text"><span class="toc-number">2.9.</span> <span class="toc-text">parse(CharSequence text)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text-DateTimeFormatter-formatter"><span class="toc-number">2.10.</span> <span class="toc-text">parse(CharSequence text, DateTimeFormatter formatter)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-number">3.</span> <span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#atStartOfDay"><span class="toc-number">3.1.</span> <span class="toc-text">atStartOfDay()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atStartOfDay-ZoneId-zone"><span class="toc-number">3.2.</span> <span class="toc-text">atStartOfDay(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-int-hour-int-minute"><span class="toc-number">3.3.</span> <span class="toc-text">atTime(int hour, int minute)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-int-hour-int-minute-int-second"><span class="toc-number">3.4.</span> <span class="toc-text">atTime(int hour, int minute, int second)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-int-hour-int-minute-int-second-int-nanoOfSecond"><span class="toc-number">3.5.</span> <span class="toc-text">atTime(int hour, int minute, int second, int nanoOfSecond)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-LocalTime-time"><span class="toc-number">3.6.</span> <span class="toc-text">atTime(LocalTime time)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-OffsetTime-time"><span class="toc-number">3.7.</span> <span class="toc-text">atTime(OffsetTime time)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#compareTo-ChronoLocalDate-other"><span class="toc-number">3.8.</span> <span class="toc-text">compareTo(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isAfter-ChronoLocalDate-other"><span class="toc-number">3.9.</span> <span class="toc-text">isAfter(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isBefore-ChronoLocalDate-other"><span class="toc-number">3.10.</span> <span class="toc-text">isBefore(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isEqual-ChronoLocalDate-other"><span class="toc-number">3.11.</span> <span class="toc-text">isEqual(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#format-DateTimeFormatter-formatter"><span class="toc-number">3.12.</span> <span class="toc-text">format(DateTimeFormatter formatter)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isSupported-TemporalField-field"><span class="toc-number">3.13.</span> <span class="toc-text">isSupported(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isSupported-TemporalUnit-unit"><span class="toc-number">3.14.</span> <span class="toc-text">isSupported(TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#get-TemporalField-field"><span class="toc-number">3.15.</span> <span class="toc-text">get(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getLong-TemporalField-field"><span class="toc-number">3.16.</span> <span class="toc-text">getLong(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getDayOfMonth"><span class="toc-number">3.17.</span> <span class="toc-text">getDayOfMonth()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getDayOfWeek"><span class="toc-number">3.18.</span> <span class="toc-text">getDayOfWeek()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getDayOfYear"><span class="toc-number">3.19.</span> <span class="toc-text">getDayOfYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getEra"><span class="toc-number">3.20.</span> <span class="toc-text">getEra()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getMonth"><span class="toc-number">3.21.</span> <span class="toc-text">getMonth()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getMonthValue"><span class="toc-number">3.22.</span> <span class="toc-text">getMonthValue()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getYear"><span class="toc-number">3.23.</span> <span class="toc-text">getYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isLeapYear"><span class="toc-number">3.24.</span> <span class="toc-text">isLeapYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lengthOfMonth"><span class="toc-number">3.25.</span> <span class="toc-text">lengthOfMonth()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lengthOfYear"><span class="toc-number">3.26.</span> <span class="toc-text">lengthOfYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minus-long-amountToSubtract-TemporalUnit-unit"><span class="toc-number">3.27.</span> <span class="toc-text">minus(long amountToSubtract, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minus-TemporalAmount-amountToSubtract"><span class="toc-number">3.28.</span> <span class="toc-text">minus(TemporalAmount amountToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusDays-long-daysToSubtract"><span class="toc-number">3.29.</span> <span class="toc-text">minusDays(long daysToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusMonths-long-monthsToSubtract"><span class="toc-number">3.30.</span> <span class="toc-text">minusMonths(long monthsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusWeeks-long-weeksToSubtract"><span class="toc-number">3.31.</span> <span class="toc-text">minusWeeks(long weeksToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusYears-long-yearsToSubtract"><span class="toc-number">3.32.</span> <span class="toc-text">minusYears(long yearsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plus-long-amountToSubtract-TemporalUnit-unit"><span class="toc-number">3.33.</span> <span class="toc-text">plus(long amountToSubtract, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plus-TemporalAmount-amountToSubtract"><span class="toc-number">3.34.</span> <span class="toc-text">plus(TemporalAmount amountToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusDays-long-daysToSubtract"><span class="toc-number">3.35.</span> <span class="toc-text">plusDays(long daysToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusMonths-long-monthsToSubtract"><span class="toc-number">3.36.</span> <span class="toc-text">plusMonths(long monthsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusWeeks-long-weeksToSubtract"><span class="toc-number">3.37.</span> <span class="toc-text">plusWeeks(long weeksToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusYears-long-yearsToSubtract"><span class="toc-number">3.38.</span> <span class="toc-text">plusYears(long yearsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#query-TemporalQuery-lt-R-gt-query"><span class="toc-number">3.39.</span> <span class="toc-text">query(TemporalQuery&lt;R&gt; query)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#range-TemporalField-field"><span class="toc-number">3.40.</span> <span class="toc-text">range(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toEpochDay"><span class="toc-number">3.41.</span> <span class="toc-text">toEpochDay()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#until-ChronoLocalDate-endDateExclusive"><span class="toc-number">3.42.</span> <span class="toc-text">until(ChronoLocalDate endDateExclusive)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#until-Temporal-endExclusive-TemporalUnit-unit"><span class="toc-number">3.43.</span> <span class="toc-text">until(Temporal endExclusive, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#with-TemporalField-field-long-newValue"><span class="toc-number">3.44.</span> <span class="toc-text">with(TemporalField field, long newValue)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withDayOfMonth-int-dayOfMonth"><span class="toc-number">3.45.</span> <span class="toc-text">withDayOfMonth(int dayOfMonth)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withDayOfYear-int-dayOfYear"><span class="toc-number">3.46.</span> <span class="toc-text">withDayOfYear(int dayOfYear)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withMonth-int-month"><span class="toc-number">3.47.</span> <span class="toc-text">withMonth(int month)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withYear-int-year"><span class="toc-number">3.48.</span> <span class="toc-text">withYear(int year)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#with-TemporalAdjuster-adjuster"><span class="toc-number">3.49.</span> <span class="toc-text">with(TemporalAdjuster adjuster)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95"><span class="toc-number">3.50.</span> <span class="toc-text">未演示方法</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-number">4.</span> <span class="toc-text">参考文献</span></a></li></ol>
                </div>
            
            <hr />
            <div itemprop="articleBody"><p><code>LocalDate</code> 类用来表示日期，由三个成员变量 <code>year</code> 、 <code>month</code> 、 <code>day</code> 组成，大部分成员方法是操作三个成员变量的过程，如查询由这三个变量组成的其他的时间分量，对三个变量进行加、减或重新赋予新值等等操作。</p>
<h3 id="公共常量"><a href="#公共常量" class="headerlink" title="公共常量"></a>公共常量</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* MAX：localDate对象能表示日期的最大值。</span></span><br><span class="line"><span class="comment">* MIN：localDate对象能表示日期的最小值。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    System.out.println(LocalDate.MAX); <span class="comment">// 输出 +999999999-12-31</span></span><br><span class="line">    System.out.println(LocalDate.MIN); <span class="comment">// 输出 -999999999-01-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<br>

<h3 id="静态方法"><a href="#静态方法" class="headerlink" title="静态方法"></a>静态方法</h3><h4 id="from-TemporalAccessor-temporal"><a href="#from-TemporalAccessor-temporal" class="headerlink" title="from(TemporalAccessor temporal)"></a>from(TemporalAccessor temporal)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* from(TemporalAccessor temporal)</span></span><br><span class="line"><span class="comment">* 作用：从其他包含年月日数据的时间对象获取localDate对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> LocalDateTime.parse(<span class="string">&quot;2023-01-01T12:00:00&quot;</span>);</span><br><span class="line">    System.out.println(LocalDate.from(dateTime01)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="now"><a href="#now" class="headerlink" title="now()"></a>now()</h4><h4 id="now-ZoneId-zone"><a href="#now-ZoneId-zone" class="headerlink" title="now(ZoneId zone)"></a>now(ZoneId zone)</h4><h4 id="now-Clock-clock"><a href="#now-Clock-clock" class="headerlink" title="now(Clock clock)"></a>now(Clock clock)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* now()</span></span><br><span class="line"><span class="comment">* 作用：从操作系统获取日期数据。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* now(ZoneId zone)</span></span><br><span class="line"><span class="comment">* 作用：获取其他时区此刻的日期。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* now(Clock clock)</span></span><br><span class="line"><span class="comment">* 作用：从clock对象获取日期数据。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span> &#123;</span><br><span class="line">    System.out.println(LocalDate.now()); <span class="comment">// 输出 2023-05-04</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;America/Los_Angeles&quot;</span>);</span><br><span class="line">    System.out.println(LocalDate.now(zoneId01)); <span class="comment">// 输出 2023-05-04</span></span><br><span class="line"></span><br><span class="line">    <span class="type">Instant</span> <span class="variable">instant01</span> <span class="operator">=</span> Instant.parse(<span class="string">&quot;2023-01-02T06:00:00Z&quot;</span>);</span><br><span class="line">    <span class="type">Clock</span> <span class="variable">fixedClock01</span> <span class="operator">=</span> Clock.fixed(instant01, zoneId01);</span><br><span class="line">    System.out.println(LocalDate.now(fixedClock01)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="of-int-year-int-month-int-dayOfMonth"><a href="#of-int-year-int-month-int-dayOfMonth" class="headerlink" title="of(int year, int month, int dayOfMonth)"></a>of(int year, int month, int dayOfMonth)</h4><h4 id="of-int-year-Month-month-int-dayOfMonth"><a href="#of-int-year-Month-month-int-dayOfMonth" class="headerlink" title="of(int year, Month month, int dayOfMonth)"></a>of(int year, Month month, int dayOfMonth)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* of(int year, int month, int dayOfMonth)</span></span><br><span class="line"><span class="comment">* of(int year, Month month, int dayOfMonth)</span></span><br><span class="line"><span class="comment">* 作用：给定年月日数据构建LocalDate对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span> &#123;</span><br><span class="line">    System.out.println(LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">    System.out.println(LocalDate.of(<span class="number">2023</span>, Month.JANUARY, <span class="number">1</span>)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="ofEpochDay-long-epochDay"><a href="#ofEpochDay-long-epochDay" class="headerlink" title="ofEpochDay(long epochDay)"></a>ofEpochDay(long epochDay)</h4><h4 id="ofYearDay-int-year-int-dayOfYear"><a href="#ofYearDay-int-year-int-dayOfYear" class="headerlink" title="ofYearDay(int year, int dayOfYear)"></a>ofYearDay(int year, int dayOfYear)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* ofEpochDay(long epochDay)</span></span><br><span class="line"><span class="comment">* 作用：给定距离EPOCH日期的天数构建localDate对象。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* ofYearDay(int year, int dayOfYear)</span></span><br><span class="line"><span class="comment">* 作用：给定年份和天数构建localDate对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test04</span><span class="params">()</span> &#123;</span><br><span class="line">    System.out.println(LocalDate.ofEpochDay(<span class="number">0</span>)); <span class="comment">// 输出 1970-01-01</span></span><br><span class="line">    System.out.println(LocalDate.ofEpochDay(<span class="number">1</span>)); <span class="comment">// 输出 1970-01-02</span></span><br><span class="line"></span><br><span class="line">    System.out.println(LocalDate.ofYearDay(<span class="number">2023</span>, <span class="number">1</span>)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">    System.out.println(LocalDate.ofYearDay(<span class="number">2023</span>, Month.OCTOBER.firstDayOfYear(<span class="literal">false</span>))); <span class="comment">// 输出 2023-10-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="parse-CharSequence-text"><a href="#parse-CharSequence-text" class="headerlink" title="parse(CharSequence text)"></a>parse(CharSequence text)</h4><h4 id="parse-CharSequence-text-DateTimeFormatter-formatter"><a href="#parse-CharSequence-text-DateTimeFormatter-formatter" class="headerlink" title="parse(CharSequence text, DateTimeFormatter formatter)"></a>parse(CharSequence text, DateTimeFormatter formatter)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* parse(CharSequence text)</span></span><br><span class="line"><span class="comment">* parse(CharSequence text, DateTimeFormatter formatter)</span></span><br><span class="line"><span class="comment">* 作用：将字符串解析成localDate对象，字符串默认格式yyyy-MM-dd，formatter用来指定字符串的格式。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test05</span><span class="params">()</span> &#123;</span><br><span class="line">    System.out.println(LocalDate.parse(<span class="string">&quot;2023-01-01&quot;</span>)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line"></span><br><span class="line">    <span class="type">DateTimeFormatter</span> <span class="variable">df01</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy/MM/dd&quot;</span>);</span><br><span class="line">    System.out.println(LocalDate.parse(<span class="string">&quot;2023/01/01&quot;</span>, df01)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<br>

<h3 id="成员方法"><a href="#成员方法" class="headerlink" title="成员方法"></a>成员方法</h3><h4 id="atStartOfDay"><a href="#atStartOfDay" class="headerlink" title="atStartOfDay()"></a>atStartOfDay()</h4><h4 id="atStartOfDay-ZoneId-zone"><a href="#atStartOfDay-ZoneId-zone" class="headerlink" title="atStartOfDay(ZoneId zone)"></a>atStartOfDay(ZoneId zone)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* atStartOfDay()</span></span><br><span class="line"><span class="comment">* atStartOfDay(ZoneId zone)</span></span><br><span class="line"><span class="comment">* 作用：给localDate对象添加00:00时间数据使其生成localDateTime对象，</span></span><br><span class="line"><span class="comment">*      若再添加zone时区参数则生成含有时区概念的zonedDateTime对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test01</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.parse(<span class="string">&quot;2023-01-01&quot;</span>);</span><br><span class="line">    <span class="type">LocalDateTime</span> <span class="variable">dateTime01</span> <span class="operator">=</span> date01.atStartOfDay();</span><br><span class="line">    System.out.println(dateTime01); <span class="comment">// 输出 2023-01-01T00:00</span></span><br><span class="line"></span><br><span class="line">    <span class="type">ZoneId</span> <span class="variable">zoneId01</span> <span class="operator">=</span> ZoneId.of(<span class="string">&quot;Asia/Shanghai&quot;</span>);</span><br><span class="line">    <span class="type">ZonedDateTime</span> <span class="variable">zonedDateTime01</span> <span class="operator">=</span> date01.atStartOfDay(zoneId01);</span><br><span class="line">    System.out.println(zonedDateTime01); <span class="comment">// 输出 2023-01-01T00:00+08:00[Asia/Shanghai]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="atTime-int-hour-int-minute"><a href="#atTime-int-hour-int-minute" class="headerlink" title="atTime(int hour, int minute)"></a>atTime(int hour, int minute)</h4><h4 id="atTime-int-hour-int-minute-int-second"><a href="#atTime-int-hour-int-minute-int-second" class="headerlink" title="atTime(int hour, int minute, int second)"></a>atTime(int hour, int minute, int second)</h4><h4 id="atTime-int-hour-int-minute-int-second-int-nanoOfSecond"><a href="#atTime-int-hour-int-minute-int-second-int-nanoOfSecond" class="headerlink" title="atTime(int hour, int minute, int second, int nanoOfSecond)"></a>atTime(int hour, int minute, int second, int nanoOfSecond)</h4><h4 id="atTime-LocalTime-time"><a href="#atTime-LocalTime-time" class="headerlink" title="atTime(LocalTime time)"></a>atTime(LocalTime time)</h4><h4 id="atTime-OffsetTime-time"><a href="#atTime-OffsetTime-time" class="headerlink" title="atTime(OffsetTime time)"></a>atTime(OffsetTime time)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* atTime(int hour, int minute)</span></span><br><span class="line"><span class="comment">* atTime(int hour, int minute, int second)</span></span><br><span class="line"><span class="comment">* atTime(int hour, int minute, int second, int nanoOfSecond)</span></span><br><span class="line"><span class="comment">* atTime(LocalTime time)</span></span><br><span class="line"><span class="comment">* atTime(OffsetTime time)</span></span><br><span class="line"><span class="comment">* 作用：给定时分秒数据生成localDateTime对象。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test02</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.parse(<span class="string">&quot;2023-01-01&quot;</span>);</span><br><span class="line">    System.out.println(date01.atTime(<span class="number">9</span>, <span class="number">0</span>, <span class="number">0</span>)); <span class="comment">// 输出 2023-01-01T09:00</span></span><br><span class="line"></span><br><span class="line">    <span class="type">LocalTime</span> <span class="variable">time01</span> <span class="operator">=</span> LocalTime.parse(<span class="string">&quot;08:00:00&quot;</span>);</span><br><span class="line">    System.out.println(date01.atTime(time01)); <span class="comment">// 输出 2023-01-01T08:00</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="compareTo-ChronoLocalDate-other"><a href="#compareTo-ChronoLocalDate-other" class="headerlink" title="compareTo(ChronoLocalDate other)"></a>compareTo(ChronoLocalDate other)</h4><h4 id="isAfter-ChronoLocalDate-other"><a href="#isAfter-ChronoLocalDate-other" class="headerlink" title="isAfter(ChronoLocalDate other)"></a>isAfter(ChronoLocalDate other)</h4><h4 id="isBefore-ChronoLocalDate-other"><a href="#isBefore-ChronoLocalDate-other" class="headerlink" title="isBefore(ChronoLocalDate other)"></a>isBefore(ChronoLocalDate other)</h4><h4 id="isEqual-ChronoLocalDate-other"><a href="#isEqual-ChronoLocalDate-other" class="headerlink" title="isEqual(ChronoLocalDate other)"></a>isEqual(ChronoLocalDate other)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* compareTo(ChronoLocalDate other)</span></span><br><span class="line"><span class="comment">* isAfter(ChronoLocalDate other)</span></span><br><span class="line"><span class="comment">* isBefore(ChronoLocalDate other)</span></span><br><span class="line"><span class="comment">* isEqual(ChronoLocalDate other)</span></span><br><span class="line"><span class="comment">* 作用：比较两个localDate对象大小，other为null时报NPE异常。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test03</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date02</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date03</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">2</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date04</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">    System.out.println(date01.compareTo(date02)); <span class="comment">// 输出 0（相等）</span></span><br><span class="line">    System.out.println(date01.compareTo(date03)); <span class="comment">// 输出 -1（date01小于date03）</span></span><br><span class="line">    System.out.println(date01.compareTo(date04)); <span class="comment">// NPE异常</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.isEqual(date02)); <span class="comment">// 输出 true</span></span><br><span class="line">    System.out.println(date01.isBefore(date03)); <span class="comment">// 输出 true</span></span><br><span class="line">    System.out.println(date01.isBefore(date04)); <span class="comment">// NPE异常</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="format-DateTimeFormatter-formatter"><a href="#format-DateTimeFormatter-formatter" class="headerlink" title="format(DateTimeFormatter formatter)"></a>format(DateTimeFormatter formatter)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* format(DateTimeFormatter formatter)</span></span><br><span class="line"><span class="comment">* 作用：localDate对象根据指定的格式输出字符串。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test04</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="type">DateTimeFormatter</span> <span class="variable">df01</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy-MM-dd&quot;</span>);</span><br><span class="line">    <span class="type">DateTimeFormatter</span> <span class="variable">df02</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy/MM/dd&quot;</span>);</span><br><span class="line">    <span class="type">DateTimeFormatter</span> <span class="variable">df03</span> <span class="operator">=</span> DateTimeFormatter.ofPattern(<span class="string">&quot;yyyy年MM月dd日&quot;</span>);</span><br><span class="line"></span><br><span class="line">    System.out.println(date01.format(df01)); <span class="comment">// 输出 2023-01-01</span></span><br><span class="line">    System.out.println(date01.format(df02)); <span class="comment">// 输出 2023/01/01</span></span><br><span class="line">    System.out.println(date01.format(df03)); <span class="comment">// 输出 2023年01月01日</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="isSupported-TemporalField-field"><a href="#isSupported-TemporalField-field" class="headerlink" title="isSupported(TemporalField field)"></a>isSupported(TemporalField field)</h4><h4 id="isSupported-TemporalUnit-unit"><a href="#isSupported-TemporalUnit-unit" class="headerlink" title="isSupported(TemporalUnit unit)"></a>isSupported(TemporalUnit unit)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* isSupported(TemporalField field)</span></span><br><span class="line"><span class="comment">* 作用：判断对象是否支持指定的时间分量。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* isSupported(TemporalUnit unit)</span></span><br><span class="line"><span class="comment">* 作用：判断对象是否支持指定的时间单位。时间单位有年、月、日、时、分、秒、毫秒、纳秒、微妙等等。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test05</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">2</span>, <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">    System.out.println(date01.isSupported(ChronoField.YEAR)); <span class="comment">// 输出 true</span></span><br><span class="line">    System.out.println(date01.isSupported(ChronoField.HOUR_OF_DAY)); <span class="comment">// 输出 false</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.isSupported(ChronoUnit.YEARS)); <span class="comment">// 输出 true</span></span><br><span class="line">    System.out.println(date01.isSupported(ChronoUnit.HOURS)); <span class="comment">// 输出 false</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="get-TemporalField-field"><a href="#get-TemporalField-field" class="headerlink" title="get(TemporalField field)"></a>get(TemporalField field)</h4><h4 id="getLong-TemporalField-field"><a href="#getLong-TemporalField-field" class="headerlink" title="getLong(TemporalField field)"></a>getLong(TemporalField field)</h4><h4 id="getDayOfMonth"><a href="#getDayOfMonth" class="headerlink" title="getDayOfMonth()"></a>getDayOfMonth()</h4><h4 id="getDayOfWeek"><a href="#getDayOfWeek" class="headerlink" title="getDayOfWeek()"></a>getDayOfWeek()</h4><h4 id="getDayOfYear"><a href="#getDayOfYear" class="headerlink" title="getDayOfYear()"></a>getDayOfYear()</h4><h4 id="getEra"><a href="#getEra" class="headerlink" title="getEra()"></a>getEra()</h4><h4 id="getMonth"><a href="#getMonth" class="headerlink" title="getMonth()"></a>getMonth()</h4><h4 id="getMonthValue"><a href="#getMonthValue" class="headerlink" title="getMonthValue()"></a>getMonthValue()</h4><h4 id="getYear"><a href="#getYear" class="headerlink" title="getYear()"></a>getYear()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* get(TemporalField field)</span></span><br><span class="line"><span class="comment">* getLong(TemporalField field)</span></span><br><span class="line"><span class="comment">* 作用：获取指定的时间分量，如年、月、日、时、分、秒、星期、一年中的第几天等等，详细可查看ChronoField类。</span></span><br><span class="line"><span class="comment">*      但不是所有时间分量都能获取。如localDate对象无法获取时、分、秒等时间分量。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* getDayOfMonth()</span></span><br><span class="line"><span class="comment">* getDayOfWeek()</span></span><br><span class="line"><span class="comment">* getDayOfYear()</span></span><br><span class="line"><span class="comment">* getEra()</span></span><br><span class="line"><span class="comment">* getMonth()</span></span><br><span class="line"><span class="comment">* getMonthValue()</span></span><br><span class="line"><span class="comment">* getYear()</span></span><br><span class="line"><span class="comment">* 作用：作用类似get(TemporalField field)。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test06</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">2</span>, <span class="number">1</span>);</span><br><span class="line">    System.out.println(date01.get(ChronoField.YEAR)); <span class="comment">// 输出 2023</span></span><br><span class="line">    System.out.println(date01.get(ChronoField.MONTH_OF_YEAR)); <span class="comment">// 输出 2</span></span><br><span class="line">    System.out.println(date01.get(ChronoField.DAY_OF_MONTH)); <span class="comment">// 输出 1</span></span><br><span class="line">    System.out.println(date01.get(ChronoField.DAY_OF_WEEK)); <span class="comment">// 输出 3</span></span><br><span class="line">    System.out.println(date01.get(ChronoField.DAY_OF_YEAR)); <span class="comment">// 输出 32</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.getYear()); <span class="comment">// 输出 2023</span></span><br><span class="line">    System.out.println(date01.getMonthValue()); <span class="comment">// 输出 2</span></span><br><span class="line">    System.out.println(date01.getDayOfMonth()); <span class="comment">// 输出 1</span></span><br><span class="line">    System.out.println(date01.getDayOfWeek()); <span class="comment">// 输出 WEDNESDAY</span></span><br><span class="line">    System.out.println(date01.getDayOfYear()); <span class="comment">// 输出 32</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="isLeapYear"><a href="#isLeapYear" class="headerlink" title="isLeapYear()"></a>isLeapYear()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* isLeapYear()</span></span><br><span class="line"><span class="comment">* 作用：判断是否是闰年</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test07</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2000</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date02</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    System.out.println(date01.isLeapYear()); <span class="comment">// 输出 true</span></span><br><span class="line">    System.out.println(date02.isLeapYear()); <span class="comment">// 输出 false</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="lengthOfMonth"><a href="#lengthOfMonth" class="headerlink" title="lengthOfMonth()"></a>lengthOfMonth()</h4><h4 id="lengthOfYear"><a href="#lengthOfYear" class="headerlink" title="lengthOfYear()"></a>lengthOfYear()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* lengthOfMonth()</span></span><br><span class="line"><span class="comment">* 作用：获取localDate对象的月份的天数</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* lengthOfYear()</span></span><br><span class="line"><span class="comment">* 作用：获取localDate对象的年份的天数</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test08</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2000</span>, <span class="number">2</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date02</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">2</span>, <span class="number">1</span>);</span><br><span class="line">    System.out.println(date01.lengthOfMonth()); <span class="comment">// 输出 29</span></span><br><span class="line">    System.out.println(date02.lengthOfMonth()); <span class="comment">// 输出 28</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.lengthOfYear()); <span class="comment">// 输出 366</span></span><br><span class="line">    System.out.println(date02.lengthOfYear()); <span class="comment">// 输出 365</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="minus-long-amountToSubtract-TemporalUnit-unit"><a href="#minus-long-amountToSubtract-TemporalUnit-unit" class="headerlink" title="minus(long amountToSubtract, TemporalUnit unit)"></a>minus(long amountToSubtract, TemporalUnit unit)</h4><h4 id="minus-TemporalAmount-amountToSubtract"><a href="#minus-TemporalAmount-amountToSubtract" class="headerlink" title="minus(TemporalAmount amountToSubtract)"></a>minus(TemporalAmount amountToSubtract)</h4><h4 id="minusDays-long-daysToSubtract"><a href="#minusDays-long-daysToSubtract" class="headerlink" title="minusDays(long daysToSubtract)"></a>minusDays(long daysToSubtract)</h4><h4 id="minusMonths-long-monthsToSubtract"><a href="#minusMonths-long-monthsToSubtract" class="headerlink" title="minusMonths(long monthsToSubtract)"></a>minusMonths(long monthsToSubtract)</h4><h4 id="minusWeeks-long-weeksToSubtract"><a href="#minusWeeks-long-weeksToSubtract" class="headerlink" title="minusWeeks(long weeksToSubtract)"></a>minusWeeks(long weeksToSubtract)</h4><h4 id="minusYears-long-yearsToSubtract"><a href="#minusYears-long-yearsToSubtract" class="headerlink" title="minusYears(long yearsToSubtract)"></a>minusYears(long yearsToSubtract)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* minus(long amountToSubtract, TemporalUnit unit)</span></span><br><span class="line"><span class="comment">* minus(TemporalAmount amountToSubtract)</span></span><br><span class="line"><span class="comment">* minusDays(long daysToSubtract)</span></span><br><span class="line"><span class="comment">* minusMonths(long monthsToSubtract)</span></span><br><span class="line"><span class="comment">* minusWeeks(long weeksToSubtract)</span></span><br><span class="line"><span class="comment">* minusYears(long yearsToSubtract)</span></span><br><span class="line"><span class="comment">* 作用：在指定的时间单位上减去固定值。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test09</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">10</span>, <span class="number">10</span>);</span><br><span class="line">    System.out.println(date01.minus(<span class="number">1</span>, ChronoUnit.YEARS)); <span class="comment">// 输出 2022-10-10</span></span><br><span class="line">    System.out.println(date01.minus(<span class="number">1</span>, ChronoUnit.MONTHS)); <span class="comment">// 输出 2023-09-10</span></span><br><span class="line">    System.out.println(date01.minus(<span class="number">1</span>, ChronoUnit.DAYS)); <span class="comment">// 输出 2023-10-09</span></span><br><span class="line"></span><br><span class="line">    <span class="type">Period</span> <span class="variable">period01</span> <span class="operator">=</span> Period.of(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    System.out.println(date01.minus(period01)); <span class="comment">// 输出 2022-09-09</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.minusYears(<span class="number">1</span>)); <span class="comment">// 输出 2022-10-10</span></span><br><span class="line">    System.out.println(date01.minusMonths(<span class="number">1</span>)); <span class="comment">// 输出 2023-09-10</span></span><br><span class="line">    System.out.println(date01.minusDays(<span class="number">1</span>)); <span class="comment">// 输出 2023-10-09</span></span><br><span class="line">    System.out.println(date01.minusWeeks(<span class="number">1</span>)); <span class="comment">// 输出 2023-10-03</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="plus-long-amountToSubtract-TemporalUnit-unit"><a href="#plus-long-amountToSubtract-TemporalUnit-unit" class="headerlink" title="plus(long amountToSubtract, TemporalUnit unit)"></a>plus(long amountToSubtract, TemporalUnit unit)</h4><h4 id="plus-TemporalAmount-amountToSubtract"><a href="#plus-TemporalAmount-amountToSubtract" class="headerlink" title="plus(TemporalAmount amountToSubtract)"></a>plus(TemporalAmount amountToSubtract)</h4><h4 id="plusDays-long-daysToSubtract"><a href="#plusDays-long-daysToSubtract" class="headerlink" title="plusDays(long daysToSubtract)"></a>plusDays(long daysToSubtract)</h4><h4 id="plusMonths-long-monthsToSubtract"><a href="#plusMonths-long-monthsToSubtract" class="headerlink" title="plusMonths(long monthsToSubtract)"></a>plusMonths(long monthsToSubtract)</h4><h4 id="plusWeeks-long-weeksToSubtract"><a href="#plusWeeks-long-weeksToSubtract" class="headerlink" title="plusWeeks(long weeksToSubtract)"></a>plusWeeks(long weeksToSubtract)</h4><h4 id="plusYears-long-yearsToSubtract"><a href="#plusYears-long-yearsToSubtract" class="headerlink" title="plusYears(long yearsToSubtract)"></a>plusYears(long yearsToSubtract)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* plus(long amountToSubtract, TemporalUnit unit)</span></span><br><span class="line"><span class="comment">* plus(TemporalAmount amountToSubtract)</span></span><br><span class="line"><span class="comment">* plusDays(long daysToSubtract)</span></span><br><span class="line"><span class="comment">* plusMonths(long monthsToSubtract)</span></span><br><span class="line"><span class="comment">* plusWeeks(long weeksToSubtract)</span></span><br><span class="line"><span class="comment">* plusYears(long yearsToSubtract)</span></span><br><span class="line"><span class="comment">* 作用：在指定的时间单位上加上固定值。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test10</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">10</span>, <span class="number">10</span>);</span><br><span class="line">    System.out.println(date01.plus(<span class="number">1</span>, ChronoUnit.YEARS)); <span class="comment">// 输出 2024-10-10</span></span><br><span class="line">    System.out.println(date01.plus(<span class="number">1</span>, ChronoUnit.MONTHS)); <span class="comment">// 输出 2023-11-10</span></span><br><span class="line">    System.out.println(date01.plus(<span class="number">1</span>, ChronoUnit.DAYS)); <span class="comment">// 输出 2023-10-11</span></span><br><span class="line"></span><br><span class="line">    <span class="type">Period</span> <span class="variable">period01</span> <span class="operator">=</span> Period.of(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    System.out.println(date01.plus(period01)); <span class="comment">// 输出 2024-11-11</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.plusYears(<span class="number">1</span>)); <span class="comment">// 输出 2024-10-10</span></span><br><span class="line">    System.out.println(date01.plusMonths(<span class="number">1</span>)); <span class="comment">// 输出 2023-11-10</span></span><br><span class="line">    System.out.println(date01.plusDays(<span class="number">1</span>)); <span class="comment">// 输出 2023-10-11</span></span><br><span class="line">    System.out.println(date01.plusWeeks(<span class="number">1</span>)); <span class="comment">// 输出 2023-10-17</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="query-TemporalQuery-lt-R-gt-query"><a href="#query-TemporalQuery-lt-R-gt-query" class="headerlink" title="query(TemporalQuery&lt;R&gt; query)"></a>query(TemporalQuery&lt;R&gt; query)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* query(TemporalQuery&lt;R&gt; query)</span></span><br><span class="line"><span class="comment">* 作用：TemporalQuery是一个函数接口，有一个queryFrom(TemporalAccessor temporal)方法。</span></span><br><span class="line"><span class="comment">*      其中的temporal对象就是调用query()方法的对象。通过实现TemporalQuery接口来自定义查询日期的逻辑，</span></span><br><span class="line"><span class="comment">*      比如我有个需求需要经常查询某个日期所在的季节，或者某个日期距离下一个闰年还有多少天等等。官方没有提供这样的</span></span><br><span class="line"><span class="comment">*      查询逻辑而我们又经常需要用到，此时我们可以实现TemporalQuery接口来自定义查询逻辑。</span></span><br><span class="line"><span class="comment">*      TemporalQueries类已经为我们定义了常用的查询逻辑，具体细节可查看源码。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test11</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    TemporalQuery&lt;String&gt; querySeason = data -&gt; &#123;</span><br><span class="line">        <span class="keyword">if</span> (data.isSupported(ChronoField.MONTH_OF_YEAR) == <span class="literal">false</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="type">int</span> <span class="variable">month</span> <span class="operator">=</span> data.get(ChronoField.MONTH_OF_YEAR);</span><br><span class="line">        <span class="keyword">switch</span> (month) &#123;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">12</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;Winter&quot;</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">5</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;Spring&quot;</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">6</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">7</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">8</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;Summer&quot;</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">9</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">10</span>:</span><br><span class="line">            <span class="keyword">case</span> <span class="number">11</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;Autumn&quot;</span>;</span><br><span class="line">            <span class="keyword">default</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;Unexpected value: &quot;</span> + month;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">    System.out.println(date01.query(querySeason)); <span class="comment">// 输出 Winter</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="range-TemporalField-field"><a href="#range-TemporalField-field" class="headerlink" title="range(TemporalField field)"></a>range(TemporalField field)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* range(TemporalField field)</span></span><br><span class="line"><span class="comment">* 作用：获取localDate对象相关时间分量的范围。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test12</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    System.out.println(date01.range(ChronoField.MONTH_OF_YEAR)); <span class="comment">// 输出 1 - 12</span></span><br><span class="line">    System.out.println(date01.range(ChronoField.DAY_OF_MONTH)); <span class="comment">// 输出 1 - 31</span></span><br><span class="line">    System.out.println(date01.range(ChronoField.DAY_OF_WEEK)); <span class="comment">// 输出 1 - 7</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="toEpochDay"><a href="#toEpochDay" class="headerlink" title="toEpochDay()"></a>toEpochDay()</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* toEpochDay()</span></span><br><span class="line"><span class="comment">* 作用：获取localDate对象距离EPOCH日期的天数，如果在EPOCH日期之前则为负数。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test13</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">1970</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date02</span> <span class="operator">=</span> LocalDate.of(<span class="number">1970</span>, <span class="number">1</span>, <span class="number">2</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date03</span> <span class="operator">=</span> LocalDate.of(<span class="number">1969</span>, <span class="number">12</span>, <span class="number">31</span>);</span><br><span class="line">    System.out.println(date01.toEpochDay()); <span class="comment">// 输出 0</span></span><br><span class="line">    System.out.println(date02.toEpochDay()); <span class="comment">// 输出 1</span></span><br><span class="line">    System.out.println(date03.toEpochDay()); <span class="comment">// 输出 -1</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="until-ChronoLocalDate-endDateExclusive"><a href="#until-ChronoLocalDate-endDateExclusive" class="headerlink" title="until(ChronoLocalDate endDateExclusive)"></a>until(ChronoLocalDate endDateExclusive)</h4><h4 id="until-Temporal-endExclusive-TemporalUnit-unit"><a href="#until-Temporal-endExclusive-TemporalUnit-unit" class="headerlink" title="until(Temporal endExclusive, TemporalUnit unit)"></a>until(Temporal endExclusive, TemporalUnit unit)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* until(ChronoLocalDate endDateExclusive)</span></span><br><span class="line"><span class="comment">* 作用：获取两个日期之间的时间长度，返回Period对象</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* until(Temporal endExclusive, TemporalUnit unit)</span></span><br><span class="line"><span class="comment">* 作用：根据时间单位计算一个日期距离另一个日期的值。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test14</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2022</span>, <span class="number">6</span>, <span class="number">2</span>);</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date02</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">10</span>, <span class="number">10</span>);</span><br><span class="line">    System.out.println(date01.until(date02)); <span class="comment">// 输出 P1Y4M8D</span></span><br><span class="line">    System.out.println(date01.until(date02, ChronoUnit.YEARS)); <span class="comment">// 输出 1</span></span><br><span class="line">    System.out.println(date01.until(date02, ChronoUnit.MONTHS)); <span class="comment">// 输出 16</span></span><br><span class="line">    System.out.println(date01.until(date02, ChronoUnit.DAYS)); <span class="comment">// 输出 495</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="with-TemporalField-field-long-newValue"><a href="#with-TemporalField-field-long-newValue" class="headerlink" title="with(TemporalField field, long newValue)"></a>with(TemporalField field, long newValue)</h4><h4 id="withDayOfMonth-int-dayOfMonth"><a href="#withDayOfMonth-int-dayOfMonth" class="headerlink" title="withDayOfMonth(int dayOfMonth)"></a>withDayOfMonth(int dayOfMonth)</h4><h4 id="withDayOfYear-int-dayOfYear"><a href="#withDayOfYear-int-dayOfYear" class="headerlink" title="withDayOfYear(int dayOfYear)"></a>withDayOfYear(int dayOfYear)</h4><h4 id="withMonth-int-month"><a href="#withMonth-int-month" class="headerlink" title="withMonth(int month)"></a>withMonth(int month)</h4><h4 id="withYear-int-year"><a href="#withYear-int-year" class="headerlink" title="withYear(int year)"></a>withYear(int year)</h4><h4 id="with-TemporalAdjuster-adjuster"><a href="#with-TemporalAdjuster-adjuster" class="headerlink" title="with(TemporalAdjuster adjuster)"></a>with(TemporalAdjuster adjuster)</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* with(TemporalField field, long newValue)</span></span><br><span class="line"><span class="comment">* withDayOfMonth(int dayOfMonth)</span></span><br><span class="line"><span class="comment">* withDayOfYear(int dayOfYear)</span></span><br><span class="line"><span class="comment">* withMonth(int month)</span></span><br><span class="line"><span class="comment">* withYear(int year)</span></span><br><span class="line"><span class="comment">* 作用：调整localDate对象相关时间分量的值。</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* with(TemporalAdjuster adjuster)</span></span><br><span class="line"><span class="comment">* 作用：该方法跟query(TemporalQuery&lt;R&gt; query)类似，query()方法是根据给定的查询逻辑查</span></span><br><span class="line"><span class="comment">*      询localDate对象。而with()方法是根据给定的修改逻辑修改localDate对象。TemporalAdjuster</span></span><br><span class="line"><span class="comment">*      也是一个函数接口，包含Temporal adjustInto(Temporal temporal)方法。其中temporal对象</span></span><br><span class="line"><span class="comment">*      就是调用with()方法的对象，通过实现TemporalAdjuster接口实现对localDate对象的修改逻辑。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test15</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">date01</span> <span class="operator">=</span> LocalDate.of(<span class="number">2023</span>, <span class="number">10</span>, <span class="number">10</span>);</span><br><span class="line">    System.out.println(date01.with(ChronoField.YEAR, <span class="number">2022</span>)); <span class="comment">// 输出 2022-10-10</span></span><br><span class="line">    System.out.println(date01.with(ChronoField.MONTH_OF_YEAR, <span class="number">2</span>)); <span class="comment">// 输出 2023-02-10</span></span><br><span class="line"></span><br><span class="line">    System.out.println(date01.withYear(<span class="number">2022</span>)); <span class="comment">// 输出 2022-10-10</span></span><br><span class="line">    System.out.println(date01.withMonth(<span class="number">2</span>)); <span class="comment">// 输出 2023-02-10</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/** 把日期对象yyyy-MM-dd 修改为 yyyy-MM-01 **/</span></span><br><span class="line">    <span class="type">TemporalAdjuster</span> <span class="variable">adjusterDayOfMonthTo1</span> <span class="operator">=</span> date -&gt; &#123;</span><br><span class="line">    	<span class="keyword">if</span> (date.isSupported(ChronoUnit.DAYS)) &#123;</span><br><span class="line">        	<span class="keyword">return</span> date.with(ChronoField.DAY_OF_MONTH, <span class="number">1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">    &#125;;</span><br><span class="line">    System.out.println(date01.with(adjusterDayOfMonthTo1)); <span class="comment">// 输出 2023-10-01</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="未演示方法"><a href="#未演示方法" class="headerlink" title="未演示方法"></a>未演示方法</h4><ol>
<li><p>adjustInto(Temporal temporal)</p>
</li>
<li><p>equals(Object obj)</p>
</li>
<li><p>getChronology()</p>
</li>
<li><p>hashCode()</p>
</li>
</ol>
<h3 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h3><p><a target="_blank" rel="noopener" href="https://www.matools.com/api/java8">https://www.matools.com/api/java8</a></p>
</div>
        </div>
        
        <footer class="kratos-entry-footer clearfix">
            
            <div class="footer-tag clearfix">
                <div class="pull-left">
                <i class="fa fa-tags"></i>
                    <a class="tag-none-link" href="/blog/tags/Java/" rel="tag">Java</a>
                </div>
                <div class="pull-date">
                    <time datetime="2025-11-20T11:35:22.175Z" itemprop="dateModified">最后编辑：2025-11-20</time>
                </div>
            </div>
        </footer>
    </div>
    
        <nav class="navigation post-navigation clearfix" role="navigation">
            
            
            <div class="nav-next clearfix">
                <a title=" 【Java 8 新特性】时间类：LocalTime" href="/blog/2023/05/07/Java8/time/LocalTime/">下一篇 &gt;</a>
            </div>
            
        </nav>
    
    
</article>

        

            </section>

        

                
            

<section id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm">
    <!-- 文章和页面根据splitter来分割，没有的话就从头开始设置为sticky -->
    
    
                <aside id="krw-about" class="widget widget-kratos-about clearfix">
    <div class="photo-background"></div>
    <div class="photo-wrapper clearfix">
        <div class="photo-wrapper-tip text-center">
            <img class="about-photo" src="/blog/images/avatar.webp" loading="lazy" decoding="auto" />
        </div>
    </div>
    <div class="textwidget">
        <p class="text-center">极简主义</p>
    </div>
    <div class="site-meta">
        <a class="meta-item" href="/blog/archives/">
            <span class="title">
                文章
            </span>
            <span class="count">
                72
            </span>
        </a>
        <a class="meta-item" href="/blog/categories/">
            <span class="title">
                分类
            </span>
            <span class="count">
                9
            </span>
        </a>
        <a class="meta-item" href="/blog/tags/">
            <span class="title">
                标签
            </span>
            <span class="count">
                27
            </span>
        </a>
    </div>
</aside>
            
                    <div class="sticky-area">
                
                    <aside id="krw-toc" class="widget widget-kratos-toc clearfix toc-div-class" >
    <div class="photo-background"></div>
    <h4 class="widget-title no-after">
        <i class="fa fa-compass"></i>
        文章目录
        <span class="toc-progress-bar" role="progressbar" aria-label="阅读进度："></span>
    </h4>
    <div class="textwidget">
        <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1%E5%B8%B8%E9%87%8F"><span class="toc-text">公共常量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="toc-text">静态方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#from-TemporalAccessor-temporal"><span class="toc-text">from(TemporalAccessor temporal)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now"><span class="toc-text">now()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-ZoneId-zone"><span class="toc-text">now(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#now-Clock-clock"><span class="toc-text">now(Clock clock)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-int-year-int-month-int-dayOfMonth"><span class="toc-text">of(int year, int month, int dayOfMonth)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#of-int-year-Month-month-int-dayOfMonth"><span class="toc-text">of(int year, Month month, int dayOfMonth)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofEpochDay-long-epochDay"><span class="toc-text">ofEpochDay(long epochDay)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ofYearDay-int-year-int-dayOfYear"><span class="toc-text">ofYearDay(int year, int dayOfYear)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text"><span class="toc-text">parse(CharSequence text)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#parse-CharSequence-text-DateTimeFormatter-formatter"><span class="toc-text">parse(CharSequence text, DateTimeFormatter formatter)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-text">成员方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#atStartOfDay"><span class="toc-text">atStartOfDay()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atStartOfDay-ZoneId-zone"><span class="toc-text">atStartOfDay(ZoneId zone)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-int-hour-int-minute"><span class="toc-text">atTime(int hour, int minute)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-int-hour-int-minute-int-second"><span class="toc-text">atTime(int hour, int minute, int second)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-int-hour-int-minute-int-second-int-nanoOfSecond"><span class="toc-text">atTime(int hour, int minute, int second, int nanoOfSecond)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-LocalTime-time"><span class="toc-text">atTime(LocalTime time)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#atTime-OffsetTime-time"><span class="toc-text">atTime(OffsetTime time)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#compareTo-ChronoLocalDate-other"><span class="toc-text">compareTo(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isAfter-ChronoLocalDate-other"><span class="toc-text">isAfter(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isBefore-ChronoLocalDate-other"><span class="toc-text">isBefore(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isEqual-ChronoLocalDate-other"><span class="toc-text">isEqual(ChronoLocalDate other)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#format-DateTimeFormatter-formatter"><span class="toc-text">format(DateTimeFormatter formatter)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isSupported-TemporalField-field"><span class="toc-text">isSupported(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isSupported-TemporalUnit-unit"><span class="toc-text">isSupported(TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#get-TemporalField-field"><span class="toc-text">get(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getLong-TemporalField-field"><span class="toc-text">getLong(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getDayOfMonth"><span class="toc-text">getDayOfMonth()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getDayOfWeek"><span class="toc-text">getDayOfWeek()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getDayOfYear"><span class="toc-text">getDayOfYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getEra"><span class="toc-text">getEra()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getMonth"><span class="toc-text">getMonth()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getMonthValue"><span class="toc-text">getMonthValue()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getYear"><span class="toc-text">getYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isLeapYear"><span class="toc-text">isLeapYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lengthOfMonth"><span class="toc-text">lengthOfMonth()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lengthOfYear"><span class="toc-text">lengthOfYear()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minus-long-amountToSubtract-TemporalUnit-unit"><span class="toc-text">minus(long amountToSubtract, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minus-TemporalAmount-amountToSubtract"><span class="toc-text">minus(TemporalAmount amountToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusDays-long-daysToSubtract"><span class="toc-text">minusDays(long daysToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusMonths-long-monthsToSubtract"><span class="toc-text">minusMonths(long monthsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusWeeks-long-weeksToSubtract"><span class="toc-text">minusWeeks(long weeksToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#minusYears-long-yearsToSubtract"><span class="toc-text">minusYears(long yearsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plus-long-amountToSubtract-TemporalUnit-unit"><span class="toc-text">plus(long amountToSubtract, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plus-TemporalAmount-amountToSubtract"><span class="toc-text">plus(TemporalAmount amountToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusDays-long-daysToSubtract"><span class="toc-text">plusDays(long daysToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusMonths-long-monthsToSubtract"><span class="toc-text">plusMonths(long monthsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusWeeks-long-weeksToSubtract"><span class="toc-text">plusWeeks(long weeksToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#plusYears-long-yearsToSubtract"><span class="toc-text">plusYears(long yearsToSubtract)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#query-TemporalQuery-lt-R-gt-query"><span class="toc-text">query(TemporalQuery&lt;R&gt; query)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#range-TemporalField-field"><span class="toc-text">range(TemporalField field)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#toEpochDay"><span class="toc-text">toEpochDay()</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#until-ChronoLocalDate-endDateExclusive"><span class="toc-text">until(ChronoLocalDate endDateExclusive)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#until-Temporal-endExclusive-TemporalUnit-unit"><span class="toc-text">until(Temporal endExclusive, TemporalUnit unit)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#with-TemporalField-field-long-newValue"><span class="toc-text">with(TemporalField field, long newValue)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withDayOfMonth-int-dayOfMonth"><span class="toc-text">withDayOfMonth(int dayOfMonth)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withDayOfYear-int-dayOfYear"><span class="toc-text">withDayOfYear(int dayOfYear)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withMonth-int-month"><span class="toc-text">withMonth(int month)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#withYear-int-year"><span class="toc-text">withYear(int year)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#with-TemporalAdjuster-adjuster"><span class="toc-text">with(TemporalAdjuster adjuster)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AA%E6%BC%94%E7%A4%BA%E6%96%B9%E6%B3%95"><span class="toc-text">未演示方法</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-text">参考文献</span></a></li></ol>
    </div>
</aside>
                
                
  <aside id="krw-categories" class="widget widget-kratos-categories clearfix">
    <h4 class="widget-title"><i class="fa fa-folder"></i>分类目录</h4>
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Docker/">Docker</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Idea/">Idea</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java/">Java</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Linux/">Linux</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/MySQL/">MySQL</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Python/">Python</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Selenium/">Selenium</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SpringBoot/">SpringBoot</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SpringCloud/">SpringCloud</a><span class="category-list-count">13</span></li></ul>
  </aside>


            
                
  <aside id="krw-tags" class="widget widget-kratos-tags clearfix">
    <h4 class="widget-title"><i class="fa fa-tags"></i>标签聚合</h4>
      <div class="tag-clouds">
        <a href="/blog/tags/CORS/" style="font-size: 0.8em;">CORS</a> <a href="/blog/tags/Docker/" style="font-size: 0.8em;">Docker</a> <a href="/blog/tags/Dubbo/" style="font-size: 0.8em;">Dubbo</a> <a href="/blog/tags/ELK/" style="font-size: 0.8em;">ELK</a> <a href="/blog/tags/Elasticsearch/" style="font-size: 0.8em;">Elasticsearch</a> <a href="/blog/tags/Eureka/" style="font-size: 0.8em;">Eureka</a> <a href="/blog/tags/Feign/" style="font-size: 0.8em;">Feign</a> <a href="/blog/tags/Gateway/" style="font-size: 0.8em;">Gateway</a> <a href="/blog/tags/Idea/" style="font-size: 0.8em;">Idea</a> <a href="/blog/tags/Java/" style="font-size: 0.8em;">Java</a> <a href="/blog/tags/JavaWeb/" style="font-size: 0.8em;">JavaWeb</a> <a href="/blog/tags/Linux/" style="font-size: 0.8em;">Linux</a> <a href="/blog/tags/Maven/" style="font-size: 0.8em;">Maven</a> <a href="/blog/tags/MySQL/" style="font-size: 0.8em;">MySQL</a> <a href="/blog/tags/Mybatis/" style="font-size: 0.8em;">Mybatis</a> <a href="/blog/tags/Nacos/" style="font-size: 0.8em;">Nacos</a> <a href="/blog/tags/Pytest/" style="font-size: 0.8em;">Pytest</a> <a href="/blog/tags/Python/" style="font-size: 0.8em;">Python</a>
      </div>
  </aside>

            
                
  <aside id="krw-posts" class="widget widget-kratos-posts">
  <h4 class="widget-title"><i class="fa fa-file"></i>最新文章</h4>
  <div class="tab-content">
      <ul class="list-group">
        
        
          
          
            <a class="list-group-item" href="/blog/2024/04/07/Java%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6/Java%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6/"><i class="fa  fa-book"></i> 【Java】常见的日志框架</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/06/SpringCloud/ElasticStack/Elasticsearch%E6%90%9C%E7%B4%A2%E8%AF%AD%E6%B3%95/"><i class="fa  fa-book"></i> 【ES】搜索语法</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/03/SpringCloud/ElasticStack/Elasticsearch%E7%B4%A2%E5%BC%95%E9%85%8D%E7%BD%AE/"><i class="fa  fa-book"></i> 【ES】索引配置</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/02/SpringCloud/ElasticStack/Kibana%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD/"><i class="fa  fa-book"></i> 【Kibana】常用功能</a>
            
          
        
          
          
            <a class="list-group-item" href="/blog/2024/04/02/SpringCloud/ElasticStack/IK%E5%88%86%E8%AF%8D%E5%99%A8/"><i class="fa  fa-book"></i> 【IK 分词器】基本使用</a>
            
          
        
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
      </ul>
  </div>
  </aside>

            
    </div>
</section>
        
        </div>
    </div>
</div>
<footer>
    <div id="footer"  >
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <ul class="kratos-social-icons">
                        <!-- Keep for compatibility -->
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        <!-- New links -->
                        
                    </ul>
                    <ul class="kratos-copyright">
                        <div>
                            <li>&copy; 2025 溪岚花的博客 版权所有.</li>
                            <li>本站已运行<span id="span_dt">Loading...</span></li>
                        </div>
                        <div>
                            <li>Theme <a href="https://github.com/Candinya/Kratos-Rebirth" target="_blank">Kratos:Rebirth</a></li>
                            <li>Site built with&nbsp;<i class="fa fa-heart throb" style="color:#d43f57"></i>&nbsp;by 林家隆.</li>
                        </div>
                        <div>
                            <li>Powered by <a href="https://hexo.io" target="_blank" rel="nofollow">Hexo</a></li>
                            <li>Hosted on <a href="https://gitee.com/" target="_blank">Gitee Pages</a></li>
                        </div>
                        <div>
                            
                            
                        </div>
                    </ul>
                </div>
            </div>
        </div>
        <div class="kr-tool text-center">
            <div class="tool">
                
                    <div class="box search-box">
                        <a href="/blog/search/">
                            <span class="fa fa-search"></span>
                        </a>
                    </div>
                
                
                    <div class="box theme-box" id="darkmode-switch">
                        <span class="fa fa-adjust"></span>
                    </div>
                
                
                
            </div>
            <div class="box gotop-box">
                <span class="fa fa-chevron-up"></span>
            </div>
        </div>
    </div>
</footer>
</div>
</div>

        <script defer src="/blog/vendors/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
<script defer src="/blog/vendors/nprogress@0.2.0/nprogress.js"></script>
<script>
    if (!window.kr) {
        window.kr = {};
    }
    window.kr.notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));
    window.kr.siteRoot = "/blog/";
</script>





    <script defer src="/blog/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

<script defer src="/blog/js/kratosr.min.js"></script>
<script defer src="/blog/js/pjax.min.js"></script>



<!-- Extra support for third-party plguins  -->


    </body>
</html>